import KimMain from './kim-main.vue'
import './iconfont/iconfont.css'
import './css/main.css'
import event from "@/kim/utils/event";
import store from "@/kim/store";

let kim = {}
// eslint-disable-next-line no-unused-vars
kim.install = function (Vue, options) {
    Vue.prototype.$msg = 'Hello I am test.js'
    Vue.prototype.$myMethod = function (arr) {
        if (arr.length < 0) {
            return false
        } else {
            arr = arr.join('Kim,连接你我')
            return arr
        }
    }

    Vue.mixin({
        methods:{
            /**
             * 注册kim内部事件监听
             * @param name
             * @param _callback
             */
            on(name, _callback) {
                event.on(name, _callback);
            },
            /**
             * 初始化数据
             * @param data{{ mine,friends,groups }}
             */
            init(data) {
                store.commit('init', data);
            },
            config(opts){
                console.log('config--',opts    )
                store.commit('config', opts);
            },
            /**
             * 打开聊天窗口
             * @param options {{ type,id,name,avatar }}
             */
            chat(options){
                this.$refs.chatbox.chat(options);
            },
            /**
             * 添加联系人
             * @param data {{type: 'group',avatar,name,id},{type: 'friend',avatar,name,id,gid}}
             **/
            addContact(data) {
                //data={type: 'group',avatar: "",name: '群组',id: "群聊ID"}
                //data={type: 'friend',avatar: "",name: '好友',id: "好友ID",gid: '好友分组ID'}
                if (data.type == 'friend') {
                    store.commit('addFriend', data);
                }
            },
            /**
             * 添加好友到主面板
             * @param data {{type: 'friend',avatar,name,id,gid}}
             **/
            addFriend(data){
                store.commit('addFriend', data);
            },
            /**
             * 添加好友到主面板
             * @param data {{type: 'group',avatar,name,id}}
             **/
            addGroup(data){
                //store.commit('addFriend', data);
            }
        }
    })

    Vue.component(KimMain.name, KimMain)
}


export default kim
